Given /^navigate to the page "([^\"]*)"$/ do |testURL|
  @browser.goto testURL
end

When /^no message appears in text_field with "([^\"]*)"="([^\"]*)"$/ do |componentTag,tagValue|
  if(@browser.text_field(componentTag.to_sym,tagValue).exists?.to_s=="true")
    raise @browser.text_field(componentTag.to_sym,tagValue).text
  else
    return
  end
end

Then /^wait till page load$/ do
  @browser.wait()
end

When /^on the page exists following text:"([^\"]*)"$/ do |value|
  @browser.text.include? value
end

When /^"([^\"]*)" component with "([^\"]*)"="([^\"]*)" avaliable$/ do |componentType, componentTag, tagValue|
  case
  when componentType=="button"
    Watir::Waiter::wait_until { @browser.button(componentTag.to_sym,tagValue).exists? }
  when componentType=="checkbox"
    Watir::Waiter::wait_until { @browser.checkbox(componentTag.to_sym,tagValue).exists? }
  when componentType=="link"
    Watir::Waiter::wait_until { @browser.link(componentTag.to_sym,tagValue).exists? }
  when componentType=="radio"
    Watir::Waiter::wait_until { @browser.radio(componentTag.to_sym,tagValue).exists? }
  when componentType=="select_list"
    Watir::Waiter::wait_until { @browser.select_list(componentTag.to_sym,tagValue).exists? }
  when componentType=="text_field"
    Watir::Waiter::wait_until { @browser.text_field(componentTag.to_sym,tagValue).exists? }
  when componentType=="form"
    Watir::Waiter::wait_until { @browser.form(componentTag.to_sym,tagValue).exists? }
  when componentType=="frame"
    Watir::Waiter::wait_until { @browser.frame(componentTag.to_sym,tagValue).exists? }
  else
    raise "component type """ + componentType + " is not valid. You can use: [button, checkbox, link, radio, select_list, text_field, form, frame] watir specific type for components call"
  end
end

Then /^type "([^\"]*)" value in text field with "([^\"]*)"="([^\"]*)"$/ do |value, componentTag, tagValue|
  @browser.text_field(componentTag.to_sym,tagValue).set(value.to_s)
end

Then /^click button with "([^\"]*)"="([^\"]*)"$/ do |componentTag, tagValue|
  @browser.button(componentTag.to_sym,tagValue).click
end

Then /^logoff clicking on link with "([^\"]*)"="([^\"]*)"$/ do |componentTag, tagValue|
  @browser.link(componentTag.to_sym,tagValue).click
end